<template>
	<view>
		<view class="bgcover no-repeat" :style="{ backgroundImage: 'url(' + cosImageUrl('head_bg.png',true) + ')' }">
			<!-- #ifdef H5 -->
			<view class="h60 flex alicen pl20">
				<view class="w40b">
					<u-icon @click="goback(1)" name="arrow-left" size="20" color="#000"></u-icon>
				</view>
				<view class="bold nowrap">注册登录</view>
			</view>
			<!-- #endif -->
			<!-- #ifdef MP-WEIXIN -->
			<view class="" :style="{'paddingTop':statusBarHeigh + 'px',}">
				<view class="flex alicen pl20" :style="{'height':menuButtonInfo.height + 'px',}">
					<view class="w40b">
						<u-icon @click="goback(1)" name="arrow-left" size="20" color="#000"></u-icon>
					</view>
					<view class="bold">注册登录</view>
				</view>
			</view>
			<!-- #endif -->
		</view>
		<view class="pl20 pr20">
			<view class="txtcen">
				<view class="pb30"></view>
				<image class="w40b h240" :src="cosImageUrl('loginlogo.png',true)" mode="aspectFill"></image>
			</view>
			<view class="pb60"></view>
			<view class="pb20">
				<u--input placeholder="请输入手机号" v-model="phone" border="bottom" clearable></u--input>
			</view>
			<view class="pb20 flex alicen between pb20 boree bdr1_bottom">
				<u--input placeholder="请输入密码或者验证码" v-model="pcode" border="none" clearable></u--input>
				<view class="col40 bold" @click="messageCode()">{{tips}}</view>
			</view>
			<view class="pb60"></view>
			<view class="flexCenter bgff5a5f colff fz36 pt20 pb20 ius100" @click="login()">登录</view>
			<view class="mt20 flexCenter borf84746 col40 ius100 border1 pt20 pb20"
				@click="navgateTo('/pages/applyRecommend/applyRecommend')">注册账号</view>
			<view class="pb20"></view>
			<view class="flexCenter">
				<image class="w40 h40" @click="agree = !agree"
					:src="agree?cosImageUrl( 'check.png',true):cosImageUrl( 'nocheck.png',true)" mode="aspectFit">
				</image>
				<view class="fz32 ml10">我已阅读并同意 <text class="col40 ml10"
						@click="navgateTo('/pages/servers/servers')">《用户协议》</text>和<text class="col40 ml10"
						@click="navgateTo('/pages/agreement/agreement')">《免责声明》</text></view>
			</view>
			<view class="pb60"></view>
			<view class="fz32 txtcen bold" @click.stop="nologinBtn()">暂不登录</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				tips: '获取验证码',
				phone: '', //保存手机号的值
				pcode: '', //收到的验证码
				agree: false, //同意用户协议
			}
		},
		methods: {
			//获取短信验证码事件
			async messageCode() {
				let p = this.checkPhone(this.phone);
				if (!p.pass) return this.showMsg(p.msg)
				let params = {
					mobile: this.phone,
					from: 'dny'
				}
				let res = await this.request.get('/api/sendSms', {
					params
				});
				if (res.code == 200) {
					this.successToShow(res.msg || '发送成功')
				}
			},
			//登录事件
			async login() {
				if (!this.agree) return this.showMsg('请同意用户协议和免责声明')
				let p = this.checkPhone(this.phone);
				if (!p.pass) return this.showMsg(p.msg)
				if (!this.pcode) return this.showMsg('请输入验证码')
				let params = {
					phone: this.phone,
					mobileCode: this.pcode
				}
				let l = await this.request.get('/api/loginMember', {
					params
				});
				if (l.code == 200) {
					let params = {
						useId: l.data.id
					}
					this.saveData('userdata', l.data)
					this.saveData('useId', l.data.id)
					let mit = await this.request.get('/api/showSubmit', {
						params
					});
					if (mit.code == 200) {
						this.successToShow(mit.msg || '注册成功', call => {
							this.saveData('userall', mit.data)
							this.navswitch('/pages/index/index')
						})
					}
				}
			},
			async nologinBtn() {
				let params = {
					phone: '18677194748',
					mobileCode: '123456'
				}
				let res = await this.request.get('/api/loginMember', {
					params
				})
				console.log('res', res)
				if (res.code == 200) {
					this.saveData('useId', res.data.id)
					this.saveData('userdata', res.data)
					this.navswitch('/pages/index/index')
				}
			}
		}
	}
</script>
<style lang="scss" scoped>

</style>